package com.zb.jsp.action.active;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.zb.jsp.service.active.ActiveService;
import com.zb.jsp.utils.IdsLink;
import com.zb.jsp.utils.StringUtil;
import com.zb.jsp.vo.active.ActiveVo;

public class ActiveAction extends ActionSupport {

	// 定义接受页面id序列的数组
	private String[] selectId;
	// 用于判断注册还是修改 的标志符
	String butFlgVal;
	// 实例化service对象
	ActiveService activeService = new ActiveService();
	// 定义activeVoList用来保存查询结果集
	private List<ActiveVo> activeVoList;
	// 用来从页面获取值的变量
	private ActiveVo activeVo;
	private ActiveVo activeVoQry;
	private String[] rightAdvertIdList;
	private List sexList;
	private List weightList;
	private List heightList;
	private List bloodList;
	private List beliefList;
	private List degreeList;
	private List industryList;
	private List incomeList;
	private List marriageList;

	/**
	 * 将页面获取到的值插入到数据库中
	 * 
	 * @return 返回查询成功标志
	 */
	public String addActive() {
		// 将页面获取到的复选框信息转换为String存到activeVo中
		activeVo.setSexRange(StringUtil.chgList2String(sexList));
		activeVo.setWeightRange(StringUtil.chgList2String(weightList));
		activeVo.setHeightRange(StringUtil.chgList2String(heightList));
		activeVo.setBloodRange(StringUtil.chgList2String(bloodList));
		activeVo.setBeliefRange(StringUtil.chgList2String(beliefList));
		activeVo.setDegreeRange(StringUtil.chgList2String(degreeList));
		activeVo.setIndustryRange(StringUtil.chgList2String(industryList));
		activeVo.setIncomeRange(StringUtil.chgList2String(incomeList));
		activeVo.setMarriage(StringUtil.chgList2String(marriageList));
		// 将信息保存到数据库中
		activeService.addTblActive(activeVo, rightAdvertIdList);
		System.out.println("dfdad");
		return "addActiveSuccess";
	}

	/**
	 * 根据页面传入的活动名称、活动开始结束时间活动状态等信息查询数据库中 的信息
	 * 
	 * @return String 返回查询页面跳转标志
	 */
	public String searchActive() {
		activeVoList = activeService
				.findActiveVoListByAdctiveVoQry(activeVoQry);
		return "searchActiveSuccess";
	}

	/**
	 * 根据页面传入的id序列删除数据库活动表及活动广告表信息
	 * 
	 * @return 返回查询方法
	 */
	public String delActive() {
		// 将页面获取到的id数组拼接成字串
		String ids = IdsLink.idsLink(selectId);
		// 调用service方法删除选中的记录
		activeService.delActives(ids);
		return searchActive();
	}

	/**
	 * 用于修改前将信息显示在修改页面的查询
	 * 
	 * @return 返回更新成功标志
	 */
	public String initUptActive() {
		// 根据ID查询广告位信息
		activeVo = activeService.findTblActiveById(activeVo.getId());
		butFlgVal = "upt";

		// 将获取到的复选框信息转化为相应的List类型
		sexList = StringUtil.chgString2List(activeVo.getSexRange());
		weightList = StringUtil.chgString2List(activeVo.getWeightRange());
		heightList = StringUtil.chgString2List(activeVo.getHeightRange());
		bloodList = StringUtil.chgString2List(activeVo.getBloodRange());
		beliefList = StringUtil.chgString2List(activeVo.getBeliefRange());
		degreeList = StringUtil.chgString2List(activeVo.getDegreeRange());
		industryList = StringUtil.chgString2List(activeVo.getIndustryRange());
		incomeList = StringUtil.chgString2List(activeVo.getIncomeRange());
		marriageList = StringUtil.chgString2List(activeVo.getMarriage());
		return "initUptActiveSuccess";
	}

	/**
	 * 更新活动信息
	 *  
	 * @return 返回更新成功标志符
	 */
	public String uptActive() {		
		// 将页面获取到的复选框信息转换为String存到activeVo中
		activeVo.setSexRange(StringUtil.chgList2String(sexList));
		activeVo.setWeightRange(StringUtil.chgList2String(weightList));
		activeVo.setHeightRange(StringUtil.chgList2String(heightList));
		activeVo.setBloodRange(StringUtil.chgList2String(bloodList));
		activeVo.setBeliefRange(StringUtil.chgList2String(beliefList));
		activeVo.setDegreeRange(StringUtil.chgList2String(degreeList));
		activeVo.setIndustryRange(StringUtil.chgList2String(industryList));
		activeVo.setIncomeRange(StringUtil.chgList2String(incomeList));
		activeVo.setMarriage(StringUtil.chgList2String(marriageList));
		
		activeService.uptTblActive(activeVo, rightAdvertIdList);
		return "UptActiveSuccess";		
	}
	
	public ActiveVo getActiveVo() {
		return activeVo;
	}

	public void setActiveVo(ActiveVo activeVo) {
		this.activeVo = activeVo;
	}

	public String[] getRightAdvertIdList() {
		return rightAdvertIdList;
	}

	public void setRightAdvertIdList(String[] rightAdvertIdList) {
		this.rightAdvertIdList = rightAdvertIdList;
	}

	public List getSexList() {
		return sexList;
	}

	public void setSexList(List sexList) {
		this.sexList = sexList;
	}

	public List getWeightList() {
		return weightList;
	}

	public void setWeightList(List weightList) {
		this.weightList = weightList;
	}

	public List getHeightList() {
		return heightList;
	}

	public void setHeightList(List heightList) {
		this.heightList = heightList;
	}

	public List getBloodList() {
		return bloodList;
	}

	public void setBloodList(List bloodList) {
		this.bloodList = bloodList;
	}

	public List getBeliefList() {
		return beliefList;
	}

	public void setBeliefList(List beliefList) {
		this.beliefList = beliefList;
	}

	public List getDegreeList() {
		return degreeList;
	}

	public void setDegreeList(List degreeList) {
		this.degreeList = degreeList;
	}

	public List getIndustryList() {
		return industryList;
	}

	public void setIndustryList(List industryList) {
		this.industryList = industryList;
	}

	public List getIncomeList() {
		return incomeList;
	}

	public void setIncomeList(List incomeList) {
		this.incomeList = incomeList;
	}

	public List getMarriageList() {
		return marriageList;
	}

	public void setMarriageList(List marriageList) {
		this.marriageList = marriageList;
	}

	public ActiveVo getActiveVoQry() {
		return activeVoQry;
	}

	public void setActiveVoQry(ActiveVo activeVoQry) {
		this.activeVoQry = activeVoQry;
	}

	public List<ActiveVo> getActiveVoList() {
		return activeVoList;
	}

	public void setActiveVoList(List<ActiveVo> activeVoList) {
		this.activeVoList = activeVoList;
	}

	public String[] getSelectId() {
		return selectId;
	}

	public void setSelectId(String[] selectId) {
		this.selectId = selectId;
	}

	public String getButFlgVal() {
		return butFlgVal;
	}

	public void setButFlgVal(String butFlgVal) {
		this.butFlgVal = butFlgVal;
	}
}
